#!/bin/bash
# 依赖：jq
set -e
function print_definition {
cat << EOF
{
    "type": "function",
    "function": {
        "name": "read_file",
        "description": "Read a specific file",
        "parameters": {
            "type": "object",
            "properties":{
                "path":{
                    "type":"string",
                    "description": "relative or absolute path of the file"
                }
            },
            "required":["path"]
        }
    }
}

EOF
exit
}
function print_system {
cat << EOF
### read_file 工具
根据文件的绝对路径或相对路径全量读取文件内容，不包含文件属性
EOF
exit
}
if [ $# -gt 0 ]; then
    if [ "$1" = '--help' ]; then
        print_system
    elif [ "$1" = '-h' ]; then
        print_system
    elif [ "$1" = '--usage' ]; then
        print_definition
    elif [ "$1" = '-?' ]; then
        print_definition
    fi
fi
if [ $# -eq 0 ]; then
    exit 1
fi

path=$(echo "$1" | jq -r '.path')
cat "$path" 1>&2
